package 领扣算法.剑指offer.链表中环的入口节点;

import java.util.HashMap;
import java.util.HashSet;

import MyThink.JVM.main;

public class Main {
    public ListNode detectCycle(ListNode head) {
        HashSet<ListNode> data=new HashSet<>();
        while (head!=null) {
            if (data.contains(head)) {
                return head;
            }
            data.add(head);
            head=head.next;
        }
        return null;
    }

    class ListNode {
     int val;
     ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }
}
